<script setup name="WorkFlow">
import {WorkFlowGetList} from "@/api/sys/workflow";
import WorkFlowCurd from "@/views/sys/workflow/curd";
import WorkFlowApproval from "@/views/sys/workflow/approval"
import Search from "./search.vue";
import {getCurrentInstance, reactive, onMounted} from "vue";

const {proxy} = getCurrentInstance();
import {useRoute} from "vue-router";

const route = useRoute();
const {hrp_user_sex, sys_is} = proxy.useDict('hrp_user_sex', 'sys_is');

onMounted(() => initPage());

const pd = reactive({
  workflowList: [],
  loading: true,
  showSearch: true,
  total: 0,
  daterangeUpdate_time: [],
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    name: null,
    enableFlag: "0"
  }
});

/** 查询流程列表 */
function getList() {
  pd.loading = true;
  if (null != pd.daterangeUpdate_time && '' != pd.daterangeUpdate_time) {
    pd.queryParams.beginTime = pd.daterangeUpdate_time[0];
    pd.queryParams.endTime = pd.daterangeUpdate_time[1];
  }
  WorkFlowGetList(pd.queryParams).then(res => {
    pd.workflowList = res.data;
    pd.total = res.total;
    pd.loading = false;
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  pd.queryParams.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  pd.queryParams.beginTime = null;
  pd.queryParams.endTime = null;
  pd.queryParams.name = null;
  pd.daterangeUpdate_time = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 新增按钮操作 */
function handleAdd() {
  let workflow = {};
  proxy.$refs["workflowCurdRef"].add(workflow);
}

/** 修改按钮操作 */
function handleEdit(workflow) {
  proxy.$refs["workflowCurdRef"].edit(workflow);
}

/** 审批按钮操作 */
function handApproval(workflow) {
  proxy.$refs["workflowApprovalRef"].approval(workflow);
}

/** 审批对话框完成后刷新界面 */
function workflowApprovalOk(operation) {
  getList();
}

/** 删除按钮操作 */
function handleDel(id) {
  proxy.$refs["workflowCurdRef"].del(id);
}

/** 对话框完成后刷新界面 */
function workflowCurdOk(operation) {
  getList();
}

function initPage() {
  pd.queryParams = {...pd.queryParams, ...route.query};
  getList();
}
let workflowSearchParams = reactive({
  title: "样例查询",
  isSingle: false,
  isButton: false,
  workflow: {}
});
</script>

<template>
  <div class="app-container">
    <el-form :model="pd.queryParams" ref="queryRef" :inline="true" v-show="pd.showSearch" label-width="68px">
      <el-form-item prop="name">
        <el-input v-model="pd.queryParams.name" placeholder="请输入搜索名称" @keyup.enter="handleQuery"/>
      </el-form-item>
      <el-form-item prop="enableFlag">
        <el-switch v-model="pd.queryParams.enableFlag" active-text="启用" inactive-text="停用"
                   active-value="0" inactive-value="1"></el-switch>
      </el-form-item>
      <el-form-item label="更新时间" style="width: 308px">
        <el-date-picker v-model="pd.daterangeUpdate_time" value-format="YYYY-MM-DD" type="daterange" range-separator="-"
                        start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="Search" @click="handleQuery">搜 索</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['sys:workflow:add']">新 增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="info" plain icon="Upload" v-hasPermi="['sys:workflow:add']">导 入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="Download" v-hasPermi="['sys:workflow:export']">导 出</el-button>
      </el-col>
      <el-col :span="1.5">
        <Search :title="workflowSearchParams.title" :isSingle="workflowSearchParams.isSingle"
                :isButton="workflowSearchParams.isButton" :workflow="workflowSearchParams.workflow" @ok=""></Search>
      </el-col>
      <right-toolbar v-model:showSearch="pd.showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="pd.loading" :data="pd.workflowList">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="名称" align="center" prop="name">
        <template #default="scope">
          <el-link type="primary" @click="handleUpdate(scope.row)" v-hasPermi="['sys:workflow:edit']">
            {{ scope.row.name }}
          </el-link>
        </template>
      </el-table-column>
      <!--      <el-table-column label="性别" align="center" prop="sex">-->
      <!--        <template #default="scope">-->
      <!--          <dict-tag :options="sys_user_sex" :value="scope.row.sex"/>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="状态" align="center" prop="state">-->
      <!--        <template #default="scope">-->
      <!--          <dict-tag :options="sys_state" :value="scope.row.state"/>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column label="启用" align="center" prop="enableFlag">
        <template #default="scope">
          <dict-tag :options="sys_is" :value="scope.row.enableFlag"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark"/>
      <el-table-column label="创建人" align="center" prop="createBy"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新人" align="center" prop="updateBy"/>
      <el-table-column label="更新时间" align="center" prop="updateTime" width="220">
        <template #default="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width" width="180">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleEdit(scope.row)" v-hasPermi="['sys:workflow:edit']">
            修改
          </el-button>
          <el-button link type="primary" icon="DataLine" @click="handApproval(scope.row)" v-hasPermi="['sys:workflow:edit']">
            审批
          </el-button>
          <el-button link type="primary" icon="More" v-hasPermi="['sys:workflow:edit']">
            其他
          </el-button>
          <el-button link type="primary" icon="Delete" @click="handleDel(scope.row.id)"
                     v-hasPermi="['sys:workflow:del']">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="pd.total > 0" :total="pd.total" v-model:page="pd.queryParams.pageNum"
                v-model:limit="pd.queryParams.pageSize" @pagination="getList"/>
    <WorkFlowCurd ref="workflowCurdRef" @ok="workflowCurdOk"></WorkFlowCurd>
    <WorkFlowApproval ref="workflowApprovalRef" @ok="workflowApprovalOk"></WorkFlowApproval>
  </div>
</template>

<style lang='scss' scoped>

</style>